using QFramework;
using QGameFramework.Models;
using QGameFramework.Systems;

namespace QGameFramework.Audio
{
    public class AudioComponent : BaseComponent
    {
        IAudioSystem m_AudioSystem;

        public override void OnInit()
        {
#if UNITY_EDITOR
            var config = this.GetModel<IGameConfig>();
            m_AudioSystem = this.GetSystem<IAudioSystem>();

            m_AudioSystem.SetMusicVolume(config.MusicValue);
            m_AudioSystem.SetSoundVolume(config.SoundValue);
            m_AudioSystem.SetVoiceVolume(config.VoiceValue);

            m_AudioSystem.SetMusicOpen(config.OpenMusic);
            m_AudioSystem.SetSoundOpen(config.OpenSound);
            m_AudioSystem.SetVoiceOpen(config.OpenVoice);
#else
            //TODO 根据设置
#endif
        }

        /// <summary>
        /// 播放声音
        /// </summary>
        /// <param name="audioClip"></param>
        public void PlaySound(string audioClip)
        {
            AudioKit.PlaySound(audioClip);
        }

        /// <summary>
        /// 播放BGM
        /// </summary>
        /// <param name="audioClip"></param>
        public void PlayMusic(string audioClip)
        {
            AudioKit.PlayMusic(audioClip);
        }

        /// <summary>
        /// 播放音效
        /// </summary>
        /// <param name="audioClip"></param>
        public void PlayVoice(string audioClip)
        {
            AudioKit.PlayVoice(audioClip);
        }
    }
}